<?php

class Nuo_Controller_Plugin_Bootstrap extends Zend_Controller_Plugin_Abstract
{
	/**
	 * Called before Zend_Controller_Front begins evaluating the
	 * request against its routes.
	 *
	 * @param Zend_Controller_Request_Abstract $request
	 * @return void
	 */
	public function routeShutdown(Zend_Controller_Request_Abstract $request)
	{
		
		/**
		 * @var string
		 * controller name
		 */
		$controller = $request -> getControllerName();
		
		/**
		 * check rule for admin.
		 */
		if (substr($controller, 0, 6) == 'admin-')
		{
			if (!Nuo::getApi('Acl') -> allow('core.admin.access', Nuo::getViewer()))
			{
				$request -> setControllerName('acl');
				$request -> setModuleName('core');
				$request -> setActionName('failure');
			}
			else
			{
				// change the layout to correct
				Nuo::setMode('admin');
				
				// or other.
				Zend_Layout::startMvc() -> setViewBasePath(APPLICATION_PATH . "/layouts/admin", 'Layout_Views');
			}
		}
		
		$controller = $request -> getControllerName();

		/**
		 * module namw
		 * @var string
		 */
		$module = $request -> getModuleName();

		/**
		 * action name
		 * @var string
		 */
		$action = $request -> getActionName();

		/**
		 * page name
		 * @var string
		 */
		$pageName = "{$module}_{$controller}_{$action}";
		
		/**
		 * set page name for later usage.
		 * 
		 */
		Nuo::setPageName($pageName);
		
	}

}
